using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Door : MonoBehaviour
{
    [Header("颜色")]
    public string color = "黄色";
    [Header("coll")]
    public GameObject collObj;
    [Header("是左右门吗")]
    public bool isLR = false;

    [Header("是随机房间门吗")]
    public bool isRandomDoor = false;
    private void Start()
    {
        collObj = transform.Find("CheckPosOne").gameObject;

        //隐藏
        collObj.GetComponent<Collider2D>().enabled = false;
    }
    //开门
    public void OpenDoor()
    {
        collObj.GetComponent<Collider2D>().enabled = false;
        //钥匙匹配，开门
        bool isOpen = GameManager.Instance.ReKey(1,color);
        //否则弹出提示
        if(isOpen)
        {
            if(isRandomDoor)
            {
                transform.parent.GetComponent<RandomRoomManager>().OpenDoor();
                CreateEffect();
                //直接返回
                return;
            }
            //移除列表
            SceneItemManager.instance.ReDoor(transform);

            if(color=="门")
            {
                AchiManager.instance.UnLockAchi("地下的秘密");
            }

            AudManager.instance.PlaySceneAud(AudManager.instance.sceneDic["门消失"], 1f);
        }
        else
        {
            string currStr = "";
            if (color == "黄色") currStr = "<color=yellow> 黄色 </color>";
            else if (color == "红色") currStr = "<color=red> 红色 </color>";
            else if (color == "蓝色") currStr = "<color=blue> 蓝色 </color>";
            else if(color=="门") currStr = "<color=yellow> 生锈</color>的 ";
            string str = "缺少" + currStr + "钥匙";
            TipSayManager.Instance.Say(str);
        }
    }
    private void OnMouseDown()
    {
        SceneItemManager.instance.clickEnemyRight = true;
        collObj.GetComponent<Collider2D>().enabled = true;
        SceneItemManager.instance.SetClickEnemy(gameObject);
    }

    //生成特效
    public void CreateEffect()
    {
        //生成特效
        GameObject effect = null;
        if (isLR)
        {
            effect = PoolManager.Instance.GetDoorEffectLr();
        }
        else
        {
            effect = PoolManager.Instance.GetDoorEffectUd();
        }
        effect.transform.position = transform.position;
    }
}
